import 'package:flutter/material.dart';
import 'package:flutterapp/src/utils/log_utils.dart';

void main() {
  runApp(MaterialApp(
    title: 'Slider',
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    home: HomePage(),
  ));
}

class HomePage extends StatefulWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Slider Demo"),
      ),
      body: buildBody(),
    );
  }

  double _currentValue = 0.0;

  buildBody() {
    return Container(
      width: 600,
      child: buildTheme(),
    );
  }

  buildTheme() {
    return Theme(
        data: ThemeData(
          sliderTheme: SliderThemeData(
              // 滑动条的高度
              trackHeight: 20,
              // 激活的颜色
              activeTrackColor: Colors.green,
              inactiveTrackColor: Color(0xff666666),
              activeTickMarkColor: Colors.red,
              inactiveTickMarkColor: Colors.blue,
              // 滑动点的颜色
              thumbColor: Colors.yellow,
              thumbShape: RoundSliderThumbShape(enabledThumbRadius: 10),
              overlayColor: Colors.red.withOpacity(0.5),
              overlayShape: RoundSliderThumbShape(enabledThumbRadius: 30),
              disabledThumbColor: Colors.red,
              valueIndicatorColor: Colors.red,
              showValueIndicator: ShowValueIndicator.always),
        ),
        child: buildSlider());
  }

  buildSlider() {
    return Slider(
        // 最小
        min: 0.0,
        // 最大
        max: 100,
        // 分段
        // divisions: 10,
        // 标签
        label: "${_currentValue.toStringAsFixed(1)}",
        // 初始值
        value: _currentValue,
        // // 激活的颜色
        // activeColor: Colors.green,
        // // 未激活的颜色
        // inactiveColor: Colors.grey,
        // 变化监听
        onChanged: (value) {
          setState(() {
            _currentValue = value;
          });
        },
        // 开始滑动监听
        onChangeStart: (value) {
          LogUtils.e("开始滑动 $value");
        },
        // 滑动结束监听
        onChangeEnd: (value) {
          LogUtils.e("结束滑动 $value");
        });
  }
}
